<script setup lang="ts">
import { ref } from 'vue'
import { toLogin } from '@/utils/navigate'

const user = ref({
  avatar: 'https://via.placeholder.com/64',
  nickname: '未登录用户',
})
function handleEdit() {
  uni.showToast({ title: '编辑资料', icon: 'none' })
}
function handleLogout() {
  uni.showToast({ title: '退出登录', icon: 'none' })
  toLogin()
}
</script>

<template>
  <PageWrapper :navbar="null">
    <!-- 个人信息区 -->
    <view class="mine-header">
      <image class="avatar" :src="user.avatar" />
      <view class="nickname">
        {{ user.nickname }}
      </view>
      <sar-button size="small" type="outline" @click="handleEdit">
        编辑资料
      </sar-button>
    </view>
    <!-- 功能区 -->
    <sar-grid clickable>
      <sar-grid-item icon="star" text="我的订单" />
      <sar-grid-item icon="star" text="我的收藏" />
      <sar-grid-item icon="star" text="设置" />
    </sar-grid>
    <!-- 退出登录 -->
    <view class="logout-btn">
      <sar-button type="default" danger block @click="handleLogout">
        退出登录
      </sar-button>
    </view>
  </PageWrapper>
</template>

<style scoped lang="scss">
.mine-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32rpx 0 16rpx 0;
  .avatar {
    width: 64rpx;
    height: 64rpx;
    border-radius: 50%;
    margin-bottom: 8rpx;
  }
  .nickname {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 8rpx;
  }
}
.logout-btn {
  margin: 32rpx 16rpx 0 16rpx;
}
</style>
